<template>
  <div class='headerParent'>

    <div
      :class="['strcture_item_wrap_top_person', { state_leave: changeStatus == 3 && toInfo.isGroup != '1', state_busy: changeStatus == 4 && toInfo.isGroup != '1', state_input_corner: changeStatus == 5 && toInfo.isGroup != '1', state_meeting: changeStatus == 6 && toInfo.isGroup != '1' }]">
      <!-- <img class="head_p_img" draggable="false" :class="{gray:changeStatus==7&&toInfo.isGroup!='1'}" :src="toInfo.isGroup=='1'?'static/image/home/groupInfo.png':!$isNull(toInfo.head)?`${$store.state.headPathUrl}${toInfo.id}${toInfo.head}.PNG?time=${new Date().getTime()}`:`static/image/home/person_${toInfo.gender==2?2:1}.png`" @click.stop.prevent='chat_view_target' :onerror="defaultImg"/> -->
      <img v-if="toInfo.id == 'fileAssistant'" class="head_p_img" draggable="false" src="static/image/word/app_transfer.png" @click.stop.prevent='chat_view_target' :onerror="defaultImg" />
      <img v-else-if="toInfo.isGroup != '1'" class="head_p_img" draggable="false" :class="{ gray: changeStatus == 7 && toInfo.isGroup != '1' }"
        :src="!$isNull(toInfo.head) ? `${$store.state.headPathUrl}${toInfo.id}${toInfo.head}.PNG` : `static/image/home/person_${toInfo.gender == 2 ? 2 : 1}.png`" @click.stop.prevent='chat_view_target'
        :onerror="defaultImg" />
      <img v-show="toInfo.isGroup == '1'" class="head_p_img" draggable="false" src="static/image/home/groupInfo.png" :onerror="defaultImg" />
      <img v-show="toInfo.isGroup == '0' && toInfo.status != '7'" class="head_status" :src="statusFn()" alt="">
    </div>
    <div class="h_p_n_w">
      <h3 @click="fn1()">{{ toInfo.name || toInfo.NAME || toInfo.LEABLE || "未知" }}</h3>
      <Tooltip v-show='toInfo.isGroup == "0" && toInfo.departmentnames' :content="'(' + (toInfo.departmentnames || '') + (!$isNull(toInfo.jobtitle) ? '-' + toInfo.jobtitle : '') + ')'" placement="bottom">
        <div v-show='toInfo.isGroup == "0" && toInfo.departmentnames' class='textOverflow cursor_default h_p_n_w_d' @click.stop.prevent="setSider">
          ( {{ toInfo.departmentnames || "" }}{{ !$isNull(toInfo.jobtitle) ? "-" + toInfo.jobtitle : "" }} )
        </div>
      </Tooltip>
      <div class="textOverflow_position" v-if="isDepartmentShow">
        <div class="textOverflow_position_content">
          <div v-for="(departmentListItem, index) in departmentList" :key="index + 'departmentList'" @click.stop.prevent="openTreeList(departmentListItem)">{{ departmentListItem.name }}</div>
        </div>
      </div>
    </div>
    <div class='chatFunction' v-show='toInfo.isGroup == "0" && toInfo.id != "fileAssistant"'>
      <template v-for='(item, index) in chatFunArray'>
        <Tooltip :content="item.title" placement="bottom" v-show="!(index == 0 && ifLinkman)" :key="'chatFunArray' + index">
          <div :class="{ add: index == 0, detail: index == 1, active: group_info_show && index == 1 }" @click.stop.prevent='chatFunClick(index)'></div>
        </Tooltip>
      </template>
      <!-- <Tooltip content="Right Bottom 文字提示" placement="right-end">
                <i-button>右下</i-button>
            </Tooltip> -->
    </div>
    <Tooltip placement="bottom" content="群设置" v-show='toInfo.isGroup == "1"'>
      <div class='chatGroupFunction'>
        <div :class="{ active: group_info_show }" @click.stop.prevent='toGroupFunction(2)'></div>
      </div>
    </Tooltip>
    <!-- <Tooltip placement="bottom" content="文件" style="margin-left:20px;">
            <div class="files_view" :class="{active:files_show}" @click.stop.prevent='filesActive'></div>
        </Tooltip> -->
  </div>
</template>

<script>
import tools from "@/utils/tools";
import { getUserInfo } from "@/api/headerParent";
import { sendDownloaded } from "@/api/homeChatMain";
export default {
  props: {
    messageTipsArr: {},
    sessionList: {},
    requestUser: {},
    control_type: {},
    remoteState: {},
    remoteType: {},
    shareImgList: {},
    chatList: {},
    broad_show_item: {},
    downloadList: {},
    sqlTable: {},
    ws: {},
    myInfo: {},
    toForwardingLocal: {
      type: Object,
    },
    isToForwardingLocal: {
      default: false,
    },
    updateFileList: {
      type: Array,
      default: () => {
        return [];
      },
    },
    toInfo: {
      type: Object,
      default: {
        id: "",
        name: "",
        isGroup: false,
      },
    },
    files_show: {
      type: Boolean,
      default: false,
    },
    group_info_show: {
      type: Boolean,
      default: false,
    },
    ifLinkman: {
      type: Boolean,
      default: false,
    },
    isDissolve: {
      type: Boolean,
      default: false,
    },
    toInfoHeadPath: {
      type: String,
      default: "",
    },
    isDepartmentShow: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      // defaultImg:'this.src="' + require('../../../static/image/home/person_1.png') + '"',
      defaultImg: 'this.src="static/image/home/person_1.png"',
      chatFunArray: [
        {
          name: "add",
          active: false,
          title: "添加联系人",
        },
        {
          name: "detail",
          active: false,
          title: "个人简介",
        },
      ], //聊天页面头部功能
      changeStatus: 1,
      departmentList: [],
    };
  },
  watch: {
    toInfo() {
      this.$forceUpdate();
    },
    status() {
      this.$forceUpdate();
    },
    updateUserStatus() {
      if (this.updateUserStatus.userId == this.toInfo.id) {
        this.changeStatus = this.updateUserStatus.status;
        this.$store.commit("Sync_User_Status", this.updateUserStatus.status); //同步推送的状态
        this.$forceUpdate();
      }
    },
    syncUserStatus() {
      this.changeStatus = this.syncUserStatus;
      this.$forceUpdate();
    },
  },
  computed: {
    updateUserStatus() {
      return this.$store.state.updateUserStatus;
    },
    syncUserStatus() {
      return this.$store.state.syncUserStatus;
    },
  },
  created() {
    console.log("绑定updateFileStatus");
    //新增外壳方法抽离
    this.windowFn();
  },
  methods: {
    updateFileStatus(
      status,
      errmsg,
      uuid,
      progress,
      fileName,
      size,
      fileId,
      receiveId,
      isGroup,
      receiveName,
      type,
      sendId,
      sendName
    ) {
      //zk14标注，上传相关
      // status 0是返回给你上传进度，1是告诉你上传成功，2是告诉你上传失败
      console.log(
        status,
        errmsg,
        uuid,
        progress,
        fileName,
        size,
        fileId,
        receiveId,
        isGroup,
        receiveName,
        type,
        sendId,
        sendName,
        "文件/图片上传成功.net壳返回参数==>>",
        this.updateFileList,
      );
      //2022/6/8 转发本地文件先存储相关信息
      if (this.isToForwardingLocal) {
        //
        this.$set(this.toForwardingLocal, "DownLoadId", fileId);
        this.$set(this.toForwardingLocal, "duration", size);
        this.$set(this.toForwardingLocal, "value", fileName);
        this.$set(this.toForwardingLocal, "type", "file");
        this.$set(this.toForwardingLocal, "isDownLoad", 1);

        console.log(this.toForwardingLocal, 203);
        // this.toForwardingLocal = {
        //   DownLoadId: fileId,
        //   duration: size,
        //   value: fileName,
        //   type: "file"
        // };
      }
      if (this.updateFileList.length > 0) {
        for (let i = 0; i < this.updateFileList.length; i++) {
          if (this.updateFileList[i].messageId == uuid) {
            this.$set(this.updateFileList[i], "progress", progress);
            this.$emit("viewUpdate");
            // this.$forceUpdate();
            if (status == "1" && fileId) {
              // var AllImgExt=".jpg|.jpeg|.gif|.bmp|.png|.swf|.tiff";
              // var extName = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();//（把路径中的所有字母全部转换为小写）
              // if(AllImgExt.indexOf(extName+"|")==-1){
              if (type != "0") {
                this.$set(this.updateFileList[i], "progress", 100);
                this.$set(this.updateFileList[i], "uploading", false);
                this.$set(this.updateFileList[i], "DownLoadId", fileId);
                this.$set(this.updateFileList[i], "isDownLoad", "self"); //新增自己发送的文件直接查看
                this.$set(this.updateFileList[i], "upload", 0);
                this.$wsSendMsg(
                  { id: receiveId, name: receiveName, isGroup: isGroup },
                  uuid,
                  "file",
                  {
                    id: fileId,
                    size: size,
                    name: fileName,
                    duration: size,
                    isDownLoad: "0",
                    DownLoadId: fileId,
                    gender: this.myInfo.gender || "1",
                    head: this.myInfo.head || "",
                  },
                  this.ws
                );
                // 新增发送文件完成后会话上移
                this.$emit("sortSessionList");
                // this.sortSessionList();
              } else {
                this.$set(this.updateFileList[i], "uploading", false);
                this.$set(this.updateFileList[i], "DownLoadId", fileId);
                this.$set(this.updateFileList[i], "upload", 0);
                this.$wsSendMsg(
                  { id: receiveId, name: receiveName, isGroup: isGroup },
                  uuid,
                  "image",
                  {
                    id: fileId,
                    size: size,
                    name: fileName,
                    duration: "32",
                    DownLoadId: fileId,
                    gender: this.myInfo.gender || "1",
                    head: this.myInfo.head || "",
                  },
                  this.ws
                );
                // 新增图片储存机制==>.net上传图片成功后，立刻把图片存储到数据库
                // 0未读 1已读
                let isRead = 0,
                  _this = this,
                  _time = new Date().getTime();
                if (isGroup == "1") {
                  isRead =
                    receiveId == this.toInfo.id || sendId == this.myInfo.id
                      ? 1
                      : 0;
                } else {
                  isRead =
                    sendId == this.toInfo.id || sendId == this.myInfo.id
                      ? 1
                      : 0;
                }
                this.$downLoad(
                  "api/v1/oim/image/download.do",
                  fileId,
                  (wt) => {
                    var fileReader = new FileReader();
                    fileReader.onload = function (w) {
                      let base64 = w.target.result.replace(
                        /^data\:.{1,40}base64\,/gi,
                        ""
                      );
                      let arr = fileName.split(".").splice(-1)[0];
                      let info = _this.$shell("SaveFileStream", [
                        _this.myInfo.id,
                        base64,
                        arr,
                      ]);
                      info = JSON.parse(info);
                      _this.$emit(
                        "insertData",
                        sendName,
                        receiveId,
                        sendId,
                        "image",
                        info.return_msg,
                        _time,
                        uuid,
                        isRead,
                        // "1",
                        "0", //zk1218修改，上传成功下载到本地之后，将issuccesssend改为0，表示已经成功上传
                        "filePath",
                        fileId,
                        32,
                        isGroup,
                        "fontSize",
                        "headUrl"
                      );
                      _this.$emit(
                        "updateSessionChat",
                        sendId,
                        receiveId,
                        sendName,
                        receiveName,
                        info.return_msg,
                        _time,
                        isGroup,
                        uuid,
                        "image",
                        32,
                        "filePath",
                        fileId,
                        "",
                        "fontSize"
                      );
                      //   _this.insertData(
                      //     sendName,
                      //     receiveId,
                      //     sendId,
                      //     "image",
                      //     info.return_msg,
                      //     _time,
                      //     uuid,
                      //     isRead,
                      //     // "1",
                      //     "0", //zk1218修改，上传成功下载到本地之后，将issuccesssend改为0，表示已经成功上传
                      //     "filePath",
                      //     fileId,
                      //     32,
                      //     isGroup,
                      //     "fontSize",
                      //     "headUrl"
                      //   );
                      //   _this.updateSessionChat(
                      //     sendId,
                      //     receiveId,
                      //     sendName,
                      //     receiveName,
                      //     info.return_msg,
                      //     _time,
                      //     isGroup,
                      //     uuid,
                      //     "image",
                      //     32,
                      //     "filePath",
                      //     fileId,
                      //     "",
                      //     "fontSize"
                      //   );
                    };
                    fileReader.readAsDataURL(wt);
                  },
                  (wt) => {
                    console.warn("error", wt);
                  }
                );
              }
              (this.updateFileList||[]).splice(i, 1);
            } else if (status == "2" || (status == "1" && !fileId)) {
              this.$message({
                message: `${fileName}发送失败,${errmsg}`,
                type: "error",
                duration: 3000,
              });
              this.$set(this.updateFileList[i], "uploading", false);
              this.$set(this.updateFileList[i], "isDownLoad", 404);
              this.$set(this.updateFileList[i], "isSuccessSend", "2");
              this.$set(this.updateFileList[i], "upload", 0);
              this.updatefilePath(uuid, 404, 1);
            }
          }
        }
      }
      // 新增文章上传图片
      this.$store.commit("Is_Article_Id", fileId);
      //上传结束

      if (status == "1" && fileId) {
        let ccfw = this.$store.state.chatChooseFileWait
        console.log('net壳000',ccfw)
        if(ccfw){
          let newWaitArr = ccfw.waitArr
          newWaitArr.forEach(it=>{
            if(it.messageId === uuid){
              it.fileId = fileId
            }
          })
          this.$store.commit('setChatChooseFileWait',{
            waitArr: ccfw.waitArr,
            myInfoId: ccfw.myInfoId,
            toInfoId: ccfw.toInfoId,
            type: 'done',
          })
        }
        console.log('net壳0001',this.$store.state.chatChooseFileWait)
        //return false
        if (type != "0") {
          this.$wsSendMsg(
            { id: receiveId, name: receiveName, isGroup: isGroup },
            uuid,
            "file",
            {
              id: fileId,
              size: size,
              name: fileName,
              duration: size,
              isDownLoad: "0",
              DownLoadId: fileId,
              gender: this.myInfo.gender || "1",
              head: this.myInfo.head || "",
            },
            this.ws
          );
          // 新增发送文件完成后会话上移
          console.log('net壳111',ccfw)
          this.$emit("sortSessionList");
        } else {
          this.$wsSendMsg(
            { id: receiveId, name: receiveName, isGroup: isGroup },
            uuid,
            "image",
            {
              id: fileId,
              size: size,
              name: fileName,
              duration: "32",
              DownLoadId: fileId,
              gender: this.myInfo.gender || "1",
              head: this.myInfo.head || "",
            },
            this.ws
          );
          console.log('net壳222',ccfw)
          // 新增图片储存机制==>.net上传图片成功后，立刻把图片存储到数据库
          // 0未读 1已读
          let isRead = 0,
            _this = this,
            _time = new Date().getTime();
          if (isGroup == "1") {
            isRead =
              receiveId == this.toInfo.id || sendId == this.myInfo.id
                ? 1
                : 0;
          } else {
            isRead =
              sendId == this.toInfo.id || sendId == this.myInfo.id
                ? 1
                : 0;
          }
          this.$downLoad(
            "api/v1/oim/image/download.do",
            fileId,
            (wt) => {
              var fileReader = new FileReader();
              fileReader.onload = function (w) {
                let base64 = w.target.result.replace(
                  /^data\:.{1,40}base64\,/gi,
                  ""
                );
                let arr = fileName.split(".").splice(-1)[0];
                let info = _this.$shell("SaveFileStream", [
                  _this.myInfo.id,
                  base64,
                  arr,
                ]);
                info = JSON.parse(info);
                _this.$emit(
                  "insertData",
                  sendName,
                  receiveId,
                  sendId,
                  "image",
                  info.return_msg,
                  _time,
                  uuid,
                  isRead,
                  // "1",
                  "0", //zk1218修改，上传成功下载到本地之后，将issuccesssend改为0，表示已经成功上传
                  "filePath",
                  fileId,
                  32,
                  isGroup,
                  "fontSize",
                  "headUrl"
                );
                _this.$emit(
                  "updateSessionChat",
                  sendId,
                  receiveId,
                  sendName,
                  receiveName,
                  info.return_msg,
                  _time,
                  isGroup,
                  uuid,
                  "image",
                  32,
                  "filePath",
                  fileId,
                  "",
                  "fontSize"
                );
              };
              fileReader.readAsDataURL(wt);
            },
            (wt) => {
              console.warn("error", wt);
            }
          );
        }
      }

    },
    //更新下载文件目录
    updatefilePath(id, path, fail) {
      console.log(id, path, fail, "更新下载文件目录");
      let isFail = "";
      if (fail) {
        isFail = `,isSuccessSend='2'`;
      }
      let rep = tools.operationalDatabase(
        `UPDATE ${this.sqlTable.messageList} SET isDownLoad='${path}'${isFail} WHERE messageId='${id}';`
      );
      let repData = tools.operationalDatabase(
        `UPDATE ${this.sqlTable.privateList} SET isDownLoad='${path}'${isFail} WHERE messageId='${id}';`
      );
    },

    broadPlayFile(item, messageId, path, dowId) {
      console.log(this.downloadList, item, dowId, path, messageId, 418);

      let donwLoadList = tools.operationalDatabase(
        `SELECT fileMap FROM ${this.sqlTable.broadcastList} WHERE messageId = '${messageId}';`,
        1
      );

      let donwLoad;

      if (donwLoadList.list.length > 0) {
        donwLoad = JSON.parse(donwLoadList.list[0].fileMap);
      } else {
        if (
          this.broad_show_item.fileMap &&
          Object.prototype.toString.call(this.broad_show_item.fileMap) ==
            "[object Array]"
        ) {
          donwLoad = this.broad_show_item.fileMap;
        } else {
          donwLoad = JSON.parse(this.broad_show_item.fileMap);
        }
      }

      donwLoad.forEach((i) => {
        if (i.downLoadId == dowId) {
          i.isDownLoad = path;
        }
      });

      let strD = JSON.stringify(donwLoad);
      let rep = tools.operationalDatabase(
        // 更改数据库下载状态
        `UPDATE ${this.sqlTable.broadcastList} SET fileMap = '${strD}' WHERE messageId='${messageId}';`
      );
    },

    // 公文待办附件下载处理
    officialRemindPlayFile(item, messageId, path) {
      this.$set(item, "filePath", path);
      console.log(this.downLoadFileList, "downLoadFileList");
      tools.operationalDatabase(
        `UPDATE ${this.sqlTable.officialRemindList} SET LOCAL_PATH = '${path}' WHERE FILE_ID = '${messageId}'`
      );
    },

    // 共享文件下载处理
    sharePlayFile(item, messageId, path) {
      // 2022/8/2 新增 共享文件下载完后调用接口推送修改下载状态
      if (item.DownLoadId && item.DownLoadId.indexOf("http") != -1) {
        sendDownloaded({
          messageKey: item.messageId,
          userId: this.myInfo.id || "",
          fromId: item.id,
          groupId: item.groupId || "",
        });
      }
      let isExist = tools.operationalDatabase(
        `SELECT FILE_ID,LOCAL_PATH FROM ${this.sqlTable.officialRemindList} WHERE FILE_ID = '${item.md5}'`,
        1
      );
      if (isExist && isExist.list && isExist.list.length == 0) {
        tools.operationalDatabase(
          `REPLACE INTO ${
            this.sqlTable.officialRemindList
          }(FILE_SORECE,FILE_ID,FILE_NAME,LOCAL_PATH,LOAD_URL,CREATE_TIME) VALUES ('02','${
            item.md5
          }','${item.sfiName}','${path}','${
            item.sfiActualPath
          }','${new Date().getTime()}')`
        );
      }
    },

    // 收藏的文件处理
    collectPlayFile(item, path) {
      this.$set(item, "collectFilePath", path);
      let value = tools.operationalDatabase(
        `SELECT VALUE FROM ${this.sqlTable.collectList} WHERE MESSAGE_ID = "${item.MESSAGE_ID}"`,
        1
      );
      if (value && value.list && value.list.length > 0) {
        let newValue = JSON.parse(value.list[0].VALUE);
        newValue.content = path;

        let a = tools.operationalDatabase(
          `UPDATE ${this.sqlTable.collectList} SET VALUE='${JSON.stringify(
            newValue
          )}' WHERE MESSAGE_ID = "${item.MESSAGE_ID}"`
        );
      }
    },

    progressDialog(state, msg, messageId, progress, path, dowId) {
      if (window.frames["iframe"]) {
        let ifream1 = window.frames[0];
        let ifream = window.frames["iframe"].contentWindow;
        console.log(ifream1, ifream, 511);
        window.addEventListener("message", (e) => {
          console.log(e, "ifream  传来的消息");
        });

        let params = {
          code: 200,
          msg: "下载成功",
          dowId,
          type: "dowmload",
        };
        // ifream.postMessage(params, "http://172.16.47.240:8081");
        // ifream.postMessage(params, this.$store.state.postmessageShareUrl);
        ifream.postMessage(params, "*");
      }
      console.log(state, msg, messageId, progress, path, dowId, "进度条进度");

      if (this.downloadList.length > 0) {
        for (let i = 0; i < this.downloadList.length; i++) {
          console.log("下载", this.downloadList[i]);
          if (
            (this.downloadList[i].messageId ||
              this.downloadList[i].MESSAGE_ID) == messageId
          ) {
            this.$set(this.downloadList[i], "loading", true);
            this.$set(this.downloadList[i], "upload", 1); // 新增
            this.$set(this.downloadList[i], "progress", progress);
            this.$emit("broadForceUpdate");
            // this.broadForceUpdate(); // 强制刷新广播详情页面
            this.$emit("viewUpdate");
            // this.$forceUpdate();
            if (state == 1) {
              if (progress == 100) {
                this.$emit("viewUpdate");
                // this.$forceUpdate();
                this.$Message.success("有1个文件完成下载!");
                this.$set(this.downloadList[i], "loading", false);
                this.$set(this.downloadList[i], "upload", 0);
                this.$set(this.downloadList[i], "progress", 100);
                this.$set(this.downloadList[i], "isDownLoad", path);
                if (this.downloadList[i].isUpload) {
                  this.$set(this.downloadList[i].isUpload, "isDownLoad", path);
                }

                //广播附件下载处理
                if (this.broad_show_item) {
                  console.log(this.downloadList[i], this.downloadList, 502);
                  this.broadPlayFile(
                    this.downloadList[i],
                    messageId,
                    path,
                    dowId
                  );
                }
                // 公文待办附件下载处理
                this.officialRemindPlayFile(
                  this.downloadList[i],
                  messageId,
                  path
                );
                // 共享文件下载处理
                this.sharePlayFile(this.downloadList[i], messageId, path);
                // 收藏文件处理
                this.collectPlayFile(this.downloadList[i], path);
                this.updatefilePath(messageId, path);
                (this.downloadList||[]).splice(i, 1);

                this.$forceUpdate();
              }
            } else if (state == 2) {
              this.$emit("viewUpdate");
              //   this.$forceUpdate();
              this.$Message.success(msg, 3);
              this.$set(this.downloadList[i], "loading", false);
              this.$set(this.downloadList[i], "upload", 0);
              this.$set(this.downloadList[i], "isDownLoad", 0);
              this.updatefilePath(messageId, 0);
              (this.downloadList||[]).splice(i, 1);
            }
          }
        }
      } else {
        if (this.chatList[1].length > 0) {
          for (let i = 0; i < this.chatList[1].length; i++) {
            if (this.chatList[1][i].messageId == messageId) {
              this.$emit("viewUpdate");
              //   this.$forceUpdate();
              this.$set(this.chatList[1][i], "loading", true);
              this.$set(this.chatList[1][i], "progress", progress);
              // this.$set(this.chatList[1][i],'upload',1);
              if (state == 1) {
                if (progress == 100) {
                  this.$emit("viewUpdate");
                  //   this.$forceUpdate();
                  this.$Message.success("有1个文件完成下载!");
                  this.$set(this.chatList[1][i], "loading", false);
                  this.$set(this.chatList[1][i], "progress", 100);
                  this.$set(this.chatList[1][i], "isDownLoad", path);
                  this.updatefilePath(messageId, path);
                }
              } else if (state == 2) {
                this.$emit("viewUpdate");
                // this.$forceUpdate();
                this.$Message.success(msg);
                this.$set(this.chatList[1][i], "isDownLoad", 0);
                this.$set(this.chatList[1][i], "upload", 0);
                this.updatefilePath(messageId, 0);
                (this.downloadList||[]).splice(i, 1);
              }
            }
          }
        }
      }
      if (this.shareImgList.length > 0) {
        // 新增分享图片下载完成后存到本地数据库
        for (let i in this.shareImgList) {
          let info = this.shareImgList[i];
          if (info.messageKey == messageId) {
            if (state == 1) {
              if (progress == 100) {
                this.$emit("viewUpdate");
                // this.$forceUpdate();
                this.$emit(
                  "insertData",
                  info.sendName,
                  info.rId,
                  info.sId,
                  info.type,
                  info.shareFilePath,
                  info.time,
                  info.messageKey,
                  info.isRead,
                  info.isSuccessSend,
                  info.url,
                  info.rValue,
                  info.duration,
                  info.isGroup,
                  info.fontSize,
                  info.headUrl,
                  ""
                );
                // this.insertData(
                //   info.sendName,
                //   info.rId,
                //   info.sId,
                //   info.type,
                //   info.shareFilePath,
                //   info.time,
                //   info.messageKey,
                //   info.isRead,
                //   info.isSuccessSend,
                //   info.url,
                //   info.rValue,
                //   info.duration,
                //   info.isGroup,
                //   info.fontSize,
                //   info.headUrl,
                //   ""
                // );
                this.$emit(
                  "updateSessionChat",
                  info.sId,
                  info.rId,
                  info.sendName,
                  info.receiveName,
                  info.shareFilePath,
                  info.time,
                  info.isGroup,
                  info.messageKey,
                  info.type,
                  info.duration,
                  info.url,
                  info.DownLoadId,
                  "",
                  info.fontSize,
                  info.sGender,
                  info.headUrl
                );
                // this.updateSessionChat(
                //   info.sId,
                //   info.rId,
                //   info.sendName,
                //   info.receiveName,
                //   info.shareFilePath,
                //   info.time,
                //   info.isGroup,
                //   info.messageKey,
                //   info.type,
                //   info.duration,
                //   info.url,
                //   info.DownLoadId,
                //   "",
                //   info.fontSize,
                //   info.sGender,
                //   info.headUrl
                // );
                (this.shareImgList||[]).splice(i, 1);
              }
            } else if (state == 2) {
              this.$emit("viewUpdate");
              //   this.$forceUpdate();
              this.$Message.warning("当前图片下载失败");
              (this.shareImgList||[]).splice(i, 1);
            }
          }
        }
      }
    },
    //获取远程控制状态
    getRemoteState(res) {
      // console.log('获取远程控制状态',res,this.$route.path)
      if (this.$route.path == "/") return;
      switch (res) {
        case "1":
          this.$store.state.connectRemoteServer = false;
          break;
        case "2":
        case "4":
          this.$emit("update:control_type", 5);
          // this.control_type = 5;
          this.$emit("update:remoteState", 5);
          // this.remoteState = 5; //建立连接
          break;
        case "3":
        case "5":
          this.$emit("update:control_type", 6);

          this.$emit("update:remoteState", 6);
          // this.control_type = 6;
          // this.remoteState = 6;
          if (this.remoteType == 1 && res == 3) {
            let initid = this.$func.uuid();
            this.ws.send(
              this.$publicSend(initid, "1.500", "1.1.1017", {
                label: 1,
                requestId: this.myInfo.id,
                receptionId: this.requestUser.id,
                type: 2,
              })
            );
          }
          // let server = this.$remoteControl("DisconnectServer", []);
          break;
      }
    },

    //获取远程注册id
    getRegisterid(res, password) {
      // console.log('获取远程注册id:',res,'密码:', password)
      if (res) {
        this.$store.state.myRegisterid = res;
        this.$store.state.myControlPassword = password;
      }
    },

    downloadImage(url, alt) {
      let _this = this;
      if (url.indexOf("http:") != -1) {
        let id = this.$utilJs.getUrlParam("id", url);
        this.$downLoad(
          "api/v1/oim/head/user/download.do",
          id,
          function (res) {
            var fileReader = new FileReader();
            fileReader.onload = function (w) {
              let base64 = w.target.result.replace(
                /^data\:.{1,40}base64\,/gi,
                ""
              );
              let info = _this.$shell("SaveFileStream", [
                _this.myInfo.id,
                base64,
                "jpg",
              ]);
              info = JSON.parse(info);
              if (info.return_code == "TRUE") {
                _this.$shell("SaveAS", [
                  _this.$isRelativePath(info.return_msg),
                  id + ".jpg",
                ]);
              }
            };
            fileReader.readAsDataURL(res);
          },
          function (res) {}
        );
      } else {
        let rep = this.$shell("SaveAS", [this.$isRelativePath(url), alt]);
      }
    },

    /**
     * 点击右下角闪烁图标传入的方法
     * @param {string} id
     * '69f175b9-45d3-45e0-87fc-4cbeeff97887'：广播标识
     * 'remind'：我的收藏
     * 'schedule'：我的日程
     * @method setSider 控制显示会话、通讯录、办公事务
     * @method workListShow 控制办公事务里的功能列表显示
     */
    getNewInfo(id) {
      //zk1224标识，点击闪烁时触发的方法
      console.log("点击闪烁时触发的方法", arguments, id);
      this.$emit("hiddenAll");
      // this.hiddenAll();
      let a = null;
      let i = 0;
      switch (id) {
        //广播
        case "69f175b9-45d3-45e0-87fc-4cbeeff97887":
          this.$emit("workListShow", 1);
          // this.workListShow(1);
          this.$emit(
            "setSider",
            2,
            true
          )(
            // this.setSider(2, true);
            (a = {})
          ),
            this.broadList.filter((item, index) => {
              if (item._id == arguments[5]) {
                a = item;
                i = index + 1;
              }
            });
          i = i % 10;
          a = { index: i - 1, item: a };
          this.setBroadItem(a);
          break;
        //待办
        case "remind":
          a = [];
          a = this.noticeList.filter((item) => {
            return item.ID == arguments[5];
          });
          this.$emit("openOfficialBox", a[0], 2);
          // this.openOfficialBox(a[0], 2);
          this.$emit("setSider", 2);
          // this.setSider(2);
          this.$emit("workListShow", 5);
          // this.workListShow(5);
          this.messageTipsArr[id].pop();
          break;
        //日程
        case "schedule":
          this.$emit("workListShow", 6);
          // this.workListShow(6);
          this.$emit("setSider", 2);
          // this.setSider(2);
          this.messageTipsArr[id].pop();
          break;
        //聊天
        default:
          console.log("聊天");
          this.$emit("setSider", 0);
          // this.setSider(0);
          for (let i = 0, len = this.sessionList.length; i < len; i++) {
            a = this.sessionList[i];
            if (a.id == id) {
              this.broad_show_item = null;
              delete this.messageTipsArr[id];
              this.$emit("toChat", a);
              // this.toChat(a);
              // if (this.toInfo.id != id) {
              //   this.toChat(a);
              // }
              break;
            }
          }
      }
    },

    // 共享文件预览文件下载获取本地路径
    previewFileDownLoad(info) {
      if (info) {
        let msg = JSON.parse(info);
        let UUID = this.$func.uuid();
        msg["messageId"] = UUID;
        this.downloadList.push(msg);
        let fileFormat = msg.sfiName.substring(
          msg.sfiName.lastIndexOf(".") + 1
        );
        this.$shell("SaveFileUrlGW", [
          this.myInfo.id,
          msg.sfiActualPath,
          UUID,
          msg.sfiName,
          fileFormat,
          "",
        ]);
      }
    },

    // 共享文件下载完成后预览
    previewFileLook(info) {
      if (info) {
        let msg = JSON.parse(info);
        let isExist = tools.operationalDatabase(
          `SELECT LOCAL_PATH FROM ${this.sqlTable.officialRemindList} WHERE FILE_ID = '${msg.md5}'`,
          1
        );
        if (isExist && isExist.list && isExist.list.length > 0) {
          let rep = this.$shell("OpenFlieByUrl", [
            isExist.list[0].LOCAL_PATH ? isExist.list[0].LOCAL_PATH : "",
          ]);
          rep = JSON.parse(rep);
          if (rep.return_code == "FALSE") {
            this.$Message.info("系统找不到指定的文件,请重新下载");
            tools.operationalDatabase(
              `DELETE FROM ${this.sqlTable.officialRemindList} WHERE FILE_ID = '${msg.md5}'`
            );
          }
        } else {
          this.$Message.info("请先下载再预览");
        }
      }
    },

    // 头像上传接口返回
    backHeadImg(res) {
      console.log("壳调用了头像上传接口返回res", res.toString());
      if (res.toString().indexOf("200") != -1) {
        console.log(res, "头像上传接口返回res");
        // this.myInfo.headImage = res.substr(4);
        if (res.toString().indexOf("200:0") != -1) {
          console.log(111);
          this.myInfo.headImage = "0";
          this.$store.commit("setUserInfo", this.myInfo);
        } else {
          console.log(222);
          this.$emit("getAndSaveUserInfo");
          // this.getAndSaveUserInfo();
        }
      }
    },

    //注册全局事件
    windowFn() {
      let arr1 = [
        "updateFileStatus",
        "progressDialog",
        "getRemoteState",
        "getRegisterid",
        "downloadImage",
        "getNewInfo",
        "previewFileDownLoad",
        "previewFileLook",
        "backHeadImg",
      ];
      arr1.forEach((i) => {
        window[i] = this[i];
      });

      // let ifream1 = window.frames[0];
      // let ifream = window.frames["iframe"].contentWindow;
      // console.log(ifream1, ifream, 962);
      // ifream.progressDialog = this.progressDialog;
    },

    statusFn() {
      switch (this.toInfo.status) {
        case "1":
          return "static/image/home/chat/icon_online_nor.png";
        case "3":
          return "static/image/home/chat/icon_leave_nor.png";
        case "4":
          return "static/image/home/chat/icon_busy_nor.png";
        case "6":
          return "static/image/home/state_meeting_corner.png";
      }
    },
    setSider() {
      this.departmentList = [];
      if (!this.isDepartmentShow) {
        getUserInfo({
          userid: this.toInfo.id,
        }).then((res) => {
          if (res.result == 200) {
            let depIds = res.data.depIds;
            let deptName = res.data.deptName;
            // let depIds = "1650/2077/2118,1650/2077/2116,1650/2077/2143";
            // let deptName = "应用/2118,JAVA/2116,武汉基地/2143,";
            if (depIds && deptName) {
              let depIdsList = depIds.split(",");
              let deptNameList = deptName.split(",");
              for (let i in depIdsList) {
                this.departmentList.push({
                  id: depIdsList[i].split("/"),
                  name: deptNameList[i].split("/")[0],
                });
              }
              // 单部门直接跳转，多部门弹出选择框
              if (depIdsList.length > 1)
                this.$emit("changeIsDepartmentShow", true);
              else this.openTreeList(this.departmentList[0]);
            }
          }
        });
      }
    },
    // 点击部门跳转到组织架构
    openTreeList(departmentListItem) {
      this.$emit("setSider", 1);
      this.$emit("openTreeList", departmentListItem.id);
      this.$emit("changeIsDepartmentShow", false);
      this.$store.commit("Anchor_Position_Organization", this.toInfo.id);
    },
    filesActive() {
      this.$emit("filesActive");
    },
    toGroupFunction(index) {
      if (this.isDissolve) {
        this.$Message.warning("您不在该群中,无法进行此操作!");
        return;
      }
      this.$emit("toGroupFunction", index);
    },
    chat_view_target(e) {
      this.$emit("chat_view_target", e);
    },
    chatFunClick(index) {
      this.$emit("chatFunClick", index);
    },
  },
};
</script>
